<?php
/**
 * Created by JetBrains PhpStorm.
 * User: thanh
 * Date: 4/14/12
 * Time: 9:12 PM
 * To change this template use File | Settings | File Templates.
 */
class CartBox extends CPortlet
{
	public function init()
	{
		//$this->title=CHtml::encode(Yii::app()->user->name);
		parent::init();
	}

	protected function renderContent()
	{
		$numPro = 0;

		$price = 0;

		if(isset(Yii::app()->session['Cart']) && Yii::app()->session['Cart'])
		{

			$cart = unserialize(Yii::app()->session['Cart']);

			foreach($cart as $item)
			{
				$numPro += $item['count'];
				$p = Product::model()->findByPk($item['id']);
				$price += $p->price*$item['count'];
			}
		}
		
		$this->render('cart_box',array('items'=>$numPro,'money'=>$price));
	}

}
